package com.wayne.testapp.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wayne.testapp.R;


/**
 * Created by wayne on 2016/9/13.
 */

public class PicTextView extends LinearLayout {
    Context context;
    private TextView tv_message;
    private ImageView iv_image;

    private String text;
    private int picId;

    public PicTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);

    }

    public PicTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context, attrs);
    }

    private void initView(Context context, AttributeSet attrs) {
        this.context = context;

        View.inflate(context, R.layout.view_no_item, this);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.picText);
        text = a.getString(R.styleable.picText_mText);
        picId = a.getResourceId(R.styleable.picText_mSrc, 0);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        tv_message = (TextView) findViewById(R.id.tv_message);
        iv_image = (ImageView) findViewById(R.id.iv_image);
        tv_message.setText(text);
        Glide.with(context).load(picId).into(iv_image);
    }
}
